use strict;
use utf8;

use MediaWiki::DumpFile;

binmode(STDOUT, ":encoding(utf-8)");

my $fn = $ARGV[0];
my $mw = MediaWiki::DumpFile->new;
my $fh;

if ($fn =~ /\.bz2$/) {
  open($fh, "bzcat $fn |") || die "can't open pipe \"bzcat $fn\"";
} else {
  open($fh, "< $fn") || die "can't open file \"$fn\"";
}

my $pages = $mw->pages($fh);

while(defined(my $page = $pages->next)) {
  my $title = $page->title;
  $title =~ s/\s/_/g;

  print join("\t", ($page->id, $title, $page->redirect, "\n"));
} 
